//
//  ZCViewController.m
//  HYHOME
//
//  Created by dllo on 16/2/26.
//  Copyright © 2016年 Mac. All rights reserved.
//

#import "ZCViewController.h"

@interface ZCViewController ()<UITextFieldDelegate>
@property (nonatomic,retain) UITextField *textFieldOfRight;


@property (nonatomic,retain)UITextField *viewOfUserzc;
@property (nonatomic,retain)UITextField *viewOfPasszc;
@property (nonatomic,retain)UITextField *viewOfqueren;
@property (nonatomic,retain)UITextField *viewOfphone;
@property (nonatomic,retain)UITextField *viewOfmail;
@end

@implementation ZCViewController


- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
    
    
    
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"注册" style:UIBarButtonItemStylePlain target:self action:@selector(regist:)];
    
     
    
    
    
    return self;
    
    
    
    
}




- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor =[ UIColor whiteColor];
    
    
    
     UILabel *name = [[UILabel alloc] initWithFrame:CGRectMake(50, 100, self.view.frame.size.width - 100, 40)];
    name.text = @"用户名:";
    
    self.viewOfUserzc = [[UITextField alloc]initWithFrame:CGRectMake(130, 100, self.view.frame.size.width - 180, 35)];
    self.viewOfUserzc.borderStyle = 3;
    self.viewOfUserzc.placeholder = @"请输入用户名";
    [self.view addSubview:name];
    [self.view addSubview:self.viewOfUserzc];
    [self.viewOfUserzc release];
    [name release];
    
    
    
    UILabel *password  = [[UILabel alloc] initWithFrame:CGRectMake(50, 160, self.view.frame.size.width - 100, 40)];
    password.text = @"密  码:";
    self.viewOfPasszc = [[UITextField alloc]initWithFrame:CGRectMake(130, 160, self.view.frame.size.width - 180, 35)];
    self.viewOfPasszc.placeholder = @"请输入密码";
    self.viewOfPasszc.borderStyle = 3;

    [self.view addSubview:self.viewOfPasszc];
    [self.view addSubview:password];
    [password release];
    [self.viewOfPasszc release];
   
    
    
     UILabel *queren = [[UILabel alloc] initWithFrame:CGRectMake(50, 220, self.view.frame.size.width - 100, 40)];
      queren.text = @"确认密码:";
    
    self.viewOfqueren = [[UITextField alloc]initWithFrame:CGRectMake(130, 220, self.view.frame.size.width - 180, 35)];
    self.viewOfqueren.borderStyle = 3;

      self.viewOfqueren.placeholder = @"请再次输入密码";
    [self.view addSubview: self.viewOfqueren];
    [self.view addSubview:queren];
    [ self.viewOfqueren release]
    ;
    [queren release];
  
    
    UILabel *phone = [[UILabel alloc] initWithFrame:CGRectMake(50, 280, self.view.frame.size.width - 100, 40)];
     phone.text = @"手机号:";
    
    self.viewOfphone = [[UITextField alloc]initWithFrame:CGRectMake(130, 280, self.view.frame.size.width - 180, 35)];
    self.viewOfphone.borderStyle = 3;
    
      self.viewOfphone.placeholder = @"请输入联系方式";
    [self.view addSubview:self.viewOfphone];
    [self.view addSubview:phone];
    [phone release];
    [self.viewOfphone release];
    
     UILabel *mail = [[UILabel alloc] initWithFrame:CGRectMake(50, 340, self.view.frame.size.width - 100, 40)];
    
    
    self.viewOfmail = [[UITextField alloc]initWithFrame:CGRectMake(130, 340, self.view.frame.size.width - 180, 35)];
    self.viewOfmail.borderStyle = 3;

     mail.text = @"邮箱:";
    self.viewOfmail.placeholder = @"请输入邮箱";
    [self.view addSubview:mail];
    
    
    
    [self.view addSubview:self.viewOfmail];
    [self.viewOfmail release];
    [mail release];
    
    self.viewOfmail.delegate = self;
    self.viewOfPasszc.delegate = self;
    self.viewOfphone.delegate = self;
    self.viewOfqueren.delegate =self;
    self.viewOfUserzc.delegate = self;
    

}



//注册事件
- (void)regist:(UIBarButtonItem *)sender{
    
    
    // 判断用户名和密码不能为空
    
        // 不为空
             // 判断两个密码是否一致.
                // 是保存本次 else 不保存
    
    
    
    
//    if (<#condition#>) { //判断用户名和密码不能为空
//        
//        if (<#condition#>) { // 判断两个密码是否一致.
//            
//            //保存本地
//            
//        } else {
//            // 提示:两个密码不一致.
//            
//        }
//        
//        
//        
//    } else {
//        
//        // else 提示:用户名和密码不能为空
//        
//        
//    }
//    
//    
//    
    
//    
//    
    // 判断用户名和密码是否为空
    if ([self.viewOfUserzc.text isEqualToString:@""] && [self.viewOfPasszc.text isEqualToString:@""]) {
        
                UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"用户名或密码不能为空" preferredStyle: UIAlertControllerStyleAlert];
        
                UIAlertAction *defaultaction2 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        
                }];
        
        
                [alert addAction:defaultaction2];
        
                [self presentViewController:alert animated:YES completion:nil];
        
        
     
        
    }else{
        
        //判断密码和确认密码是否一致
        if (![self.viewOfPasszc.text isEqualToString:self.viewOfqueren.text]) {
            
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"两次输入密码不一致" preferredStyle: UIAlertControllerStyleAlert];
            
            UIAlertAction *defaultaction2 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                
            }];
            
            
            [alert addAction:defaultaction2];
            [self presentViewController:alert animated:YES completion:nil];
            
        }else{
        
            NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
                    [user setObject:self.viewOfUserzc.text forKey:@"name"];
                    [user setObject:self.viewOfPasszc.text forKey:@"password"];
                    [user setObject:self.viewOfmail.text forKey:@"email"];
                    [user setObject:self.viewOfphone.text forKey:@"phone"];
                    [self.navigationController popViewControllerAnimated:YES];
        
        }
        
        
    }

    
 

//    if ([self.viewOfUserzc.text isEqualToString:@""] && [self.viewOfPasszc.text isEqualToString:@""]) {
//        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示"message:@"用户名或密码不能为空" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
//        [alertView show];
//        return;
////
////        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"用户名或密码不能为空" preferredStyle: UIAlertControllerStyleAlert];
////        
////        UIAlertAction *defaultaction2 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
////            
////            
////        }];
////        
////        
////        [alert addAction:defaultaction2];
////        
////        [self presentViewController:alert animated:YES completion:nil];
//        
//    }else{
//    
//    
//        //存储数据
//        NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
//        [user setObject:self.viewOfUserzc.text forKey:@"name"];
//        [user setObject:self.viewOfPasszc.text forKey:@"password"];
//        [user setObject:self.viewOfmail.text forKey:@"email"];
//        [user setObject:self.viewOfphone.text forKey:@"phone"];
////        [self.navigationController popViewControllerAnimated:YES];
//
//    }
//    
//    
//    //判断两次输入的密码是否一致
//    if (![self.viewOfPasszc.text isEqualToString:self.viewOfqueren.text]) {
//        
//        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"两次输入密码不一致" preferredStyle: UIAlertControllerStyleAlert];
//        
//        UIAlertAction *defaultaction2 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//            
//                    }];
//            
//            
//        [alert addAction:defaultaction2];
//        [self presentViewController:alert animated:YES completion:nil];
//        
//    } else {
//        //存储数据
//        NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
//        [user setObject:self.viewOfUserzc.text forKey:@"name"];
//        [user setObject:self.viewOfPasszc.text forKey:@"password"];
//        [user setObject:self.viewOfmail.text forKey:@"email"];
//        [user setObject:self.viewOfphone.text forKey:@"phone"];
//        
//        [self.navigationController popViewControllerAnimated:YES];
//
//    }
//    
//    
//    //结束编辑
//    [self.view endEditing:YES];
    
}

    
//    
//    //判断用户名和密码是否为空
//    if (self.viewOfUserzc.text == nil || [self.viewOfUserzc.text isEqualToString:@""] || self.viewOfPasszc.text == nil || [self.viewOfPasszc.text isEqualToString:@""]) {
////        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示"message:@"用户名或密码不能为空" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
////        [alertView show];
////        return;
////        
//        NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
//        [user setBool:NO forKey:@"loginState"];
//
//        
//        
//        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"用户名或密码不能为空" preferredStyle:UIAlertControllerStyleAlert];
//        UIAlertAction *defaultaction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//            
//                }];
//        
//        
//        [alert addAction:defaultaction];
//        [self presentViewController:alert animated:YES completion:nil];
//    }
//    //判断两次输入的密码是否一致
//    if (![self.viewOfPasszc.text isEqualToString:self.viewOfqueren.text]) {
//
//        
//        UIAlertController *alert2 = [UIAlertController alertControllerWithTitle:@"提示" message:@"两次输入密码不一致" preferredStyle:UIAlertControllerStyleAlert];
//        UIAlertAction *defaultaction2 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//            
//        }];
//        
//        
//        [alert2 addAction:defaultaction2];
//        [self presentViewController:alert2 animated:YES completion:nil];
//
//        
//        
//        
//    }
//    //结束编辑
//    [self.view endEditing:YES];
//
//    //存储数据
//    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
//    [user setObject:self.viewOfUserzc.text forKey:@"name"];
//    [user setObject:self.viewOfPasszc.text forKey:@"password"];
//    [user setObject:self.viewOfmail.text forKey:@"email"];
//    [user setObject:self.viewOfphone.text forKey:@"phone"];
//    //返回登录
////    [self.navigationController popViewControllerAnimated:YES];
//
    
    
//}





- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    
    [textField resignFirstResponder];
    
    return YES;
    
}


- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
